package com.example.backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.backend.entity.CaiPin;
import com.example.backend.mapper.CaiPinMapper;
import com.example.backend.service.ICaiPinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CaiPinService extends ServiceImpl<CaiPinMapper, CaiPin> implements ICaiPinService {
    @Autowired
    private CaiPinMapper caiPinMapper;
    @Override
    public boolean addCaiPin(CaiPin caiPin) {
        caiPin.setCount(0);
        caiPin.setStatus("0");
        return caiPinMapper.insert(caiPin) > 0;
    }

    @Override
    public boolean deleteCaiPin(Integer cpid) {
        return caiPinMapper.deleteById(cpid) > 0;
    }


    @Override
    public boolean batchDeleteByIds(List<String> cpidList) {
        return this.removeBatchByIds(cpidList);
    }

    @Override
    public boolean updateCaiPin(CaiPin caiPin) {
        return caiPinMapper.updateById(caiPin) > 0;
    }

    @Override
    public List<CaiPin> queryCaiPin() {
        return caiPinMapper.selectList( null);
    }

    @Override
    public CaiPin queryCaiPin(Integer cpid) {
        return caiPinMapper.selectById(cpid);
    }

    @Override
    public ArrayList<CaiPin> queryCaiPinBySjid(Integer sjid) {
//        return caiPinMapper.selectList(new LambdaQueryWrapper<CaiPin>()
//                .eq(CaiPin::getSjid, sjid)); // 查询所有 sjid 相同的菜品
        return caiPinMapper.queryCaiPinBySjid(sjid);
    }

    @Override
    public List<CaiPin> queryCaiPinByYhid(Integer yhid) {
        return caiPinMapper.queryCaiPinByYhid(yhid);
    }

    @Override
    public List<CaiPin> queryCaiPinByName(String cpmc) {
        return caiPinMapper.selectList(new LambdaQueryWrapper<CaiPin>()
                .like(CaiPin::getCpmc, cpmc));
    }


}
